package com.ruoyi.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.web.service.UserDetailsServiceImpl;
import com.ruoyi.service.UserService;
import com.ruoyi.service.impl.FrontLoginUser;
import com.ruoyi.system.domain.FApplys;
import com.ruoyi.system.domain.Users;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@RequestMapping("/api/user")
@RestController
public class IndexController {
	
	private static final Logger log = LoggerFactory.getLogger(UserDetailsServiceImpl.class);
	@Autowired
	private UserService userService;
	
	
	@GetMapping(path = "/test")
	@ResponseBody
	public String index() {
		FrontLoginUser principal = (FrontLoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		log.info(">>>>>>>>>principal{}", principal.getFrontUsers());
		return "hello world";
	}
	
	@GetMapping("/userinfo")
	@ResponseBody
	public  AjaxResult userInfo(){
		return  userService.userInfo();
	}
	
	@PostMapping(path = "/login")
	@ResponseBody
	@Anonymous
	public AjaxResult login(@RequestBody Map<String, String> params) {
		return userService.login(params);
	}
	
	@PostMapping(path = "/register")
	@ResponseBody
	@Anonymous
	public AjaxResult register(@RequestBody Users users) {
		return userService.register(users);
	}
	
	// 规章列表
	@Anonymous
	@GetMapping(path = "/guizhang_list")
	public AjaxResult guizhangList(@RequestParam Map<String, Object> params) {
		return userService.guizhangList(params);
	}
	
	@Anonymous
	@GetMapping(path = "/guizhang_detail/{id}")
	public AjaxResult guizhangDetail(@PathVariable("id") Integer id) {
		return userService.guizhangDetail(id);
	}
	
	@Anonymous
	@DeleteMapping(path = "/guizhang_del/{id}")
	public AjaxResult guizhangDelete(@PathVariable("id") Integer id) {
		return userService.guizhangDelete(id);
	}
	
	// 行政规范
	
	@Anonymous
	@GetMapping(path = "/xing_zheng_gui_fan_list")
	public AjaxResult xingzhengguifanList(@RequestParam Map<String, Object> params) {
		return userService.xing_zheng_gui_fan_list(params);
	}
	
	@Anonymous
	@GetMapping(path = "/xing_zheng_gui_fan_detail/{id}")
	public AjaxResult xingzhengguifanDetail(@PathVariable("id") Integer id) {
		return userService.xing_zheng_gui_fan_detail(id);
	}
	
	@Anonymous
	@DeleteMapping(path = "/xing_zheng_gui_fan_del/{id}")
	public AjaxResult xingzhengguifanDelete(@PathVariable("id") Integer id) {
		return userService.xing_zheng_gui_fan_delete(id);
	}
	
	// 公开指南
	@Anonymous
	@GetMapping(path = "/gong_kai_zhi_lan_list")
	public AjaxResult gongkaizhilanList(@RequestParam Map<String, Object> params) {
		return userService.gong_kai_zhi_lan_list(params);
	}
	
	// 公开制度
	@Anonymous
	@GetMapping(path = "/gong_kai_zhi_du_list")
	public AjaxResult gongkaizhiduList(@RequestParam Map<String, Object> params) {
		return userService.gong_kai_zhi_du_list(params);
	}
	
	@Anonymous
	@GetMapping(path = "/gong_kai_zhi_du_detail/{id}")
	public AjaxResult gongkaizhiduDetail(@PathVariable("id") Integer id) {
		return userService.gong_kai_zhi_du_detail(id);
	}
	
	@Anonymous
	@DeleteMapping(path = "/gong_kai_zhi_du_del/{id}")
	public AjaxResult xingzhengguiduDelete(@PathVariable("id") Integer id) {
		return userService.gong_kai_zhi_du_delete(id);
	}
	
	// 行政公开
	@Anonymous
	@GetMapping(path = "/xing_zheng_gong_kai_list")
	public AjaxResult xingzhenggongkaiList(@RequestParam Map<String, Object> params) {
		return userService.xing_zheng_gong_kai_list(params);
	}
	
	@Anonymous
	@GetMapping(path = "/xing_zheng_gong_kai_detail/{id}")
	public AjaxResult xingzhenggongkaiDetail(@PathVariable("id") Integer id) {
		return userService.xing_zheng_gong_kai_detail(id);
	}
	
	@Anonymous
	@DeleteMapping(path = "/xing_zheng_gong_kai_del/{id}")
	public AjaxResult xingzhenggongkaiDelete(@PathVariable("id") Integer id) {
		return userService.xing_zheng_gong_kai_delete(id);
	}
	
	@Anonymous
	@PostMapping(path = "/apply")
	public AjaxResult applyCreate(@RequestBody FApplys fApplys) {
		return userService.applyCreate(fApplys);
	}
	
	@Anonymous
	@GetMapping(path = "/apply")
	public AjaxResult applyCreate(@RequestParam Map<String, Object> params) {
		return userService.applyList(params);
	}
	
	@Anonymous
	@PutMapping(path = "/apply")
	public AjaxResult applyUpdate(@RequestBody Map<String, Object> params) {
		return userService.applyUpdate(params);
	}
	
	@Anonymous
	@GetMapping(path = "/area")
	public AjaxResult area() {
		return userService.areaList();
	}
	
	
}
